/*     */ package com.Ticker.tokens;
/*     */ 
/*     */ import java.text.NumberFormat;
/*     */ import java.util.Locale;
/*     */ import net.ledticker.elements.ColorModel;
/*     */ import net.ledticker.elements.Token;
/*     */ 
/*     */ public class NumberToken extends Token
/*     */ {
/*     */   private NumberFormat numberFormat;
/*     */   private String displayValue;
/*     */   protected double value;
/*     */ 
/*     */   public NumberToken()
/*     */   {
/*  37 */    
/*     */   }
/*     */ 
/*     */   public NumberToken(NumberFormat numberFormat)
/*     */   {
/*  45 */     this.value = (0.0D / 0.0D);
/*  46 */     setNumberFormat(numberFormat);
/*     */   }
/*     */ 
/*     */   public NumberToken(ColorModel colorModel)
/*     */   {
/*  55 */     setColorModel(colorModel);
/*     */   }
/*     */ 
/*     */   public NumberToken(NumberFormat numberFormat, ColorModel colorModel)
/*     */   {
/*  65 */     this(numberFormat);
/*  66 */     setColorModel(colorModel);
/*     */   }
/*     */ 
/*     */   public String getDisplayValue()
/*     */   {
/*  74 */     return this.displayValue;
/*     */   }
/*     */ 
/*     */   public void setNumberFormat(NumberFormat numberFormat)
/*     */   {
/*  85 */     if (numberFormat == null) {
/*  86 */       numberFormat = getDefaultNumberFormat();
/*     */     }
/*  88 */     this.numberFormat = numberFormat;
/*  89 */     formatDisplayValue();
/*     */   }
/*     */ 
/*     */   public void setValue(Object value)
/*     */   {
/*  98 */     if (value instanceof Number) {
/*  99 */       this.value = ((Number)value).doubleValue();
/* 100 */       formatDisplayValue();
/* 101 */       return;
/*     */     }
/*     */ 
/* 104 */     throw new IllegalArgumentException("Given value must be a java.lang.Number, not " + value.getClass().getName());
/*     */   }
/*     */ 
/*     */   private void formatDisplayValue()
/*     */   {
/* 111 */     if ((Double.isNaN(this.value)) || (Double.isInfinite(this.value)))
/* 112 */       this.displayValue = "N/A";
/*     */     else
/* 114 */       this.displayValue = this.numberFormat.format(this.value);
/*     */   }
/*     */ 
/*     */   private NumberFormat getDefaultNumberFormat()
/*     */   {
/* 123 */     NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
/* 124 */     numberFormat.setMinimumFractionDigits(2);
/* 125 */     numberFormat.setMaximumFractionDigits(2);
/* 126 */     return numberFormat;
/*     */   }
/*     */ }

/* Location:           C:\Users\os\Downloads\TrimOnline.jar
 * Qualified Name:     Ticker.tokens.NumberToken
 * JD-Core Version:    0.5.4
 */